package com.example.csetpp.config;

import com.example.csetpp.interceptor.ApiUsageInterceptor;
import com.example.csetpp.interceptor.UniqueVisitorInterceptor;
import com.example.csetpp.interceptor.UserLoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private UserLoginInterceptor userLoginInterceptor;
    @Autowired
    private UniqueVisitorInterceptor uniqueVisitorInterceptor;
    @Autowired
    private ApiUsageInterceptor apiUsageInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userLoginInterceptor)
                .addPathPatterns("/user/**",
                                 "/problem/**")
                .excludePathPatterns("/user/login",
                        "/user/verifyCode",
                        "/user/senMailCode",
                        "/user/register",
                        "/user/change-password");
        registry.addInterceptor(uniqueVisitorInterceptor)
                .addPathPatterns("/user/**")
                .excludePathPatterns("/user/login",
                        "/user/verifyCode",
                        "/user/senMailCode",
                        "/user/register",
                        "/user/change-password");
        registry.addInterceptor(apiUsageInterceptor)
                .addPathPatterns("/user/file/submit-weather-predict")
                .addPathPatterns("/user/file/stock-predict")
                .addPathPatterns("/user/file/static_weather-predict")
                .addPathPatterns("/user/file/electricity-predict");
    }
}
